package com.zensun.web.controller.system;

import com.zensun.common.annotation.Log;
import com.zensun.common.core.controller.BaseController;
import com.zensun.common.core.domain.BaseEntity;
import com.zensun.common.core.domain.R;
import com.zensun.common.enums.BusinessType;
import com.zensun.system.domain.SysMenu;
import com.zensun.system.domain.dto.SysMenuDto;
import com.zensun.system.domain.vo.SysMenuDetailVo;
import com.zensun.system.domain.vo.SysMenuTreeListVo;
import com.zensun.system.service.ISysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单信息
 *
 * @author gmk
 */
@Api(value = "菜单管理", tags = "菜单模块")
@RestController
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController {

    @Autowired
    private ISysMenuService menuService;

    /**
     * 获取菜单列表-------个人拥有的数据权限
     */
    @ApiOperation("查询菜单列表")
    @PreAuthorize("@ss.hasPermi('system:menu:list')")
    @GetMapping("/list")
    public R<List<SysMenuTreeListVo>> list(SysMenuDto menuDto) {
        return R.success(menuService.selectMenuTreeList(menuDto));
    }

    /**
     * 根据菜单编号获取详细信息
     */
    @ApiOperation("根据菜单ID获取详细信息")
    @PreAuthorize("@ss.hasPermi('system:menu:query')")
    @GetMapping(value = "/{menuId}")
    public R<SysMenuDetailVo> getInfo(@PathVariable Long menuId) {
        return R.success(menuService.selectMenuById(menuId));
    }

    /**
     * 获取菜单下拉树列表-------个人拥有的数据权限
     */
    @ApiOperation("获取菜单下拉树列表")
    @GetMapping("/treeselect")
    public R treeselect() {
        return R.success(menuService.treeselect());
    }

    /**
     * 新增菜单
     */
    @ApiOperation("新增菜单")
    @PreAuthorize("@ss.hasPermi('system:menu:add')")
    @Log(title = "菜单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@Validated(BaseEntity.AddGrop.class) @RequestBody SysMenu menu) {
        return R.toAjax(menuService.insertMenu(menu));
    }

    /**
     * 修改菜单
     */
    @ApiOperation("修改菜单")
    @PreAuthorize("@ss.hasPermi('system:menu:edit')")
    @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@Validated(BaseEntity.UpdateGrop.class) @RequestBody SysMenu menu) {
        return R.toAjax(menuService.updateMenu(menu));
    }

    /**
     * 删除菜单
     */
    @ApiOperation("删除菜单")
    @PreAuthorize("@ss.hasPermi('system:menu:remove')")
    @Log(title = "菜单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{menuId}")
    public R remove(@ApiParam("单个ID") @PathVariable("menuId") Long menuId) {
        return R.toAjax(menuService.deleteMenuById(menuId));
    }
}